package com.example.grpc.client.controller;

import io.grpc.examples.helloworld.DubboGreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class GRpcDemoController {

    @DubboReference(interfaceClass = DubboGreeterGrpc.IGreeter.class,protocol = "grpc",url = "grpc://172.16.36.76:29080",timeout=5000)
    private DubboGreeterGrpc.IGreeter greeter;

    @GetMapping("sayHello")
    public String sayHello(){
        HelloReply reply = greeter.sayHello(HelloRequest.newBuilder().setName("weiwei").build());
        log.info("reply:{}",reply.getMessage());
        return reply.getMessage();
    }
}
